package snt.org.algorithm;

import snt.org.Algorithm;
import snt.org.individuals.Individual;
import snt.org.neighborhood.demes.FixedPopulation;
import snt.org.termination.Termination;

public class GGA extends Algorithm{

	public GGA() {
		super();
	}
	
	public GGA(String name){
		super(name);
	}
	
	
	public void run() {
		
		while(!termination.isFinish()){
			
			FixedPopulation aux_pop = new FixedPopulation(population.getSize());	
			for (int i=0; i < population.getSize(); i++){
				Individual aux = mutation.mutate(crossover.cross(selection.select(population), selection.select(population)));
				evaluator.evaluate(aux);
				aux_pop.setIndividual(i, (Individual)aux.clone());					
			}
			//Elitism
			Individual best = population.getIndividual(population.getBest());
			replacement.replace(best, aux_pop);
			
			population.copyNeighborhood(aux_pop);
			Termination.increment_generation();
			
			notifyObserver();
		}
	}
}
